package app
{
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import mx.controls.Alert;
	import mx.utils.ObjectUtil;
	
	/**
	 * @author thomas fricke
	 * @version 1.0.0
	 * @date 2009-08-08
	 * @desc a GoWebTextParser() parses html text and analyses it for its contents, such 
	 * 		 as plain text, text formatting, attributes, elements, properties of elements 
	 * 		 and so on. Identified elements will be returned separately, so they can be
	 * 		 positioned well in mxml components. it also has to look for containing img-
	 * 		 tags and get their dimensions, especially height, because textareas with less 
	 * 		 text and some images causes the images to be cut, which sucks.
	 * 		 secondary goal of GoWebTextParser() is to be the fundament for the (planned) 
	 * 		 website-analysis-tool which lets users open websites and decide, which content 
	 * 		 elements they want to use for their "pseudo-rss-feeds" (this should work as 
	 * 		 bigger editorial pages use content management systems which always use the 
	 * 		 same layers (or, layer ids) to position their content).
	 **/
	public class GoWebTextParser
	{
		
//		[Bindable] public var itemGetter:GoItemGetter = GoItemGetter.getSingleton();
		
		// parsing input
		public function parseText(text:String):String {
			return text;
		}
		
		[Bindable] public var parsedItems:Array;
		public function parseContent(text:String):void {
			parsedItems = new Array();				// will contain the elements, one by one
			var currentItem:String;					// contains a tag from < to > or text
			var nonTag:String = "";					// text which is not in tags
			var plainText:String = "";				// everything else, maybe plaintext occuring
			var isPlainText:Boolean = false;		// to check for storing later
			var currentChar:String;					// currently parsed char
			var currentPos:int = 0;					// position of current char
			var isTag:Boolean = false;				// true if we're inside a tag (<)
			if(text) {
				for(var ii:int = 0; ii < text.length; ii++) {
					currentChar = text.charAt(ii);	
					// tag begins	
					if(currentChar == "<") {			// an html tag has begun
						if(nonTag != "" && isTag == false) {				// check if nonTag has content; if it does, previous was non-tag-string
							parsedItems.push(nonTag);	// then push text
							nonTag = "";				// and reset nonTag variable
						}
						isTag = true;					// so we set it
						currentItem = "<";				// setting initial char
					// tag ends
					} else if(currentChar == ">") {		// tag ended
						isTag = false
						currentItem += currentChar;		// so set end tag
						parsedItems.push(currentItem);	// move whole tag into tags array
						currentItem = "";
	//					break;							// and bye...
					// in between of a tag
					} else if(currentChar != "<" && currentChar != ">" && isTag == true) {							// normal char
						currentItem += currentChar;		// store it
					// everything else (should be non-tag-text? we'll see... - w0rks!)
					} else if(currentChar != "<" && currentChar != ">" && isTag == false) {
						nonTag += currentChar;			// and just store, pushing comes at next char at the if #1
					} else {
						isPlainText = true;
						plainText += currentChar;
					}
				}
			}
			if(parsedItems.length == 0) {
				parsedItems.push(text);
			}
			
			
		}
		

		
		
		public function GoWebTextParser()
		{
			
		}
		
	}
}